package routines

import (
	"log/slog"
	"os"
	"os/signal"
	"syscall"
)

func WaitExit() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	sig := <-sigs
	slog.Debug("application exit by signal: " + sig.String())
}

func TrigSignal(sig os.Signal) error {
	p, err := os.FindProcess(os.Getpid())
	if err != nil {
		return err
	}
	err = p.Signal(sig)
	if err != nil {
		return err
	}
	return nil
}
